package co.fitstart.admin.entity.search;

import java.util.Date;
import java.util.Map;

import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.persistence.support.Filter;
import com.demo2do.core.persistence.support.Order;
import com.demo2do.core.persistence.support.QueryBuilder;

public class OnlineExperienceSignUpSearch implements QueryBuilder {

    /** 学员名称 */
    private String name;

    private String wechat;

    /** 学员手机号 */
    private String mobile;

    /** 是否处理 */
    private Boolean handled;

    /** 开始时间（提交时间） */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date begin;

    /** 结束时间（提交时间） */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date end;

    private Order order;

    private Filter filter;

    public OnlineExperienceSignUpSearch() {
        this.order = new Order("createTime","DESC");
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public Filter getPreparedFilter(boolean refresh) {
        if(filter == null || refresh) {
            
            filter =  new Filter().addLike("name", name)
                                  .addLike("wechat", wechat)
                                  .addLike("mobile", mobile)
                                  .addDateTimeBetween("createTime", begin, end);
            
            if(handled != null && handled) {
                filter.addIsNotNull("handleTime");
            } else if(handled != null && !handled) {
                filter.addIsNull("handleTime");
            }
        }
        
        return filter;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public Order getOrder() {
        return order;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        return "FROM OnlineExperienceSignUp " + getPreparedFilter(false).getWhereSentence() + order.getSentence();
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).getParameters();
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the wechat
     */
    public String getWechat() {
        return wechat;
    }

    /**
     * @param wechat the wechat to set
     */
    public void setWechat(String wechat) {
        this.wechat = wechat;
    }

    /**
     * @return the mobile
     */
    public String getMobile() {
        return mobile;
    }

    /**
     * @param mobile the mobile to set
     */
    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    /**
     * @return the handled
     */
    public Boolean getHandled() {
        return handled;
    }

    /**
     * @param handled the handled to set
     */
    public void setHandled(Boolean handled) {
        this.handled = handled;
    }

    /**
     * @return the begin
     */
    public Date getBegin() {
        return begin;
    }

    /**
     * @param begin the begin to set
     */
    public void setBegin(Date begin) {
        this.begin = begin;
    }

    /**
     * @return the end
     */
    public Date getEnd() {
        return end;
    }

    /**
     * @param end the end to set
     */
    public void setEnd(Date end) {
        this.end = end;
    }
}
